package com.ruoyi.web.controller.dangerControl;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.dangerControl.vo.HdInstitutionVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dangerControl.domain.HdInstitution;
import com.ruoyi.dangerControl.service.IHdInstitutionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 隐患-文件制度Controller
 *
 * @author lth
 * @date 2023-12-13
 */
@RestController
@RequestMapping("/dangerControl/institution")
public class HdInstitutionController extends BaseController
{
    @Autowired
    private IHdInstitutionService hdInstitutionService;

    /**
     * 查询隐患-文件制度列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:institution:list')")
    @GetMapping("/list")
    public TableDataInfo list(HdInstitution hdInstitution)
    {
        startPage();
        List<HdInstitution> list = hdInstitutionService.selectHdInstitutionList(hdInstitution);
        return getDataTable(list);
    }

    /**
     * 导出隐患-文件制度列表
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:institution:export')")
    @Log(title = "隐患-文件制度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HdInstitution hdInstitution)
    {
        List<HdInstitution> list = hdInstitutionService.selectHdInstitutionList(hdInstitution);
        ExcelUtil<HdInstitution> util = new ExcelUtil<HdInstitution>(HdInstitution.class);
        util.exportExcel(response, list, "隐患-文件制度数据");
    }

    /**
     * 获取隐患-文件制度详细信息
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:institution:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hdInstitutionService.selectHdInstitutionById(id));
    }

    /**
     * 新增隐患-文件制度
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:institution:add')")
    @Log(title = "隐患-文件制度", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HdInstitution hdInstitution)
    {
        long id = new SnowflakeIdUtils(5, 8).nextId();
        hdInstitution.setId(id);
        hdInstitution.setCode("HD-"+(id+1));
        hdInstitution.setCreateAt(new Date());
        return toAjax(hdInstitutionService.insertHdInstitution(hdInstitution));
    }

    /**
     * 修改隐患-文件制度
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:institution:edit')")
    @Log(title = "隐患-文件制度", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HdInstitution hdInstitution)
    {
        return toAjax(hdInstitutionService.updateHdInstitution(hdInstitution));
    }

    /**
     * 删除隐患-文件制度
     */
    @PreAuthorize("@ss.hasPermi('dangerControl:institution:remove')")
    @Log(title = "隐患-文件制度", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hdInstitutionService.deleteHdInstitutionByIds(ids));
    }



    /**     文件名称模糊查询
    * @Author lth
    * @Description //TODO
    * @Date 19:26 2023/12/13
    * @Param
    * @return
     **/
    @PreAuthorize("@ss.hasPermi('dangerControl:institution:query')")
    @GetMapping("/getInfoByFileName")
    public TableDataInfo getInfoByFileName(@RequestBody HdInstitutionVo vo)
    {
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<HdInstitution> list = hdInstitutionService.getInfoByFileName(vo);
        return getDataTable(list);
    }

}
